// Copyright (C) 2012 Ato Araki @atotto. All rights reserved.

package main

import (
	"net"
	)


func sendMessage(address string, json string) error{

    tcpAddress, err := net.ResolveTCPAddr("tcp", address + ":55555")
    if err != nil {
        println("ResolveTCPAddr failed:", err.Error())
		return err
    }

	println("Connect to : " + tcpAddress.String() + "["+ tcpAddress.Network() +"]")

	conn, err := net.DialTCP("tcp", nil, tcpAddress)
    defer conn.Close()

	if err != nil {
        println("Dial failed:", err.Error())
		return err
	}

    _, err = conn.Write([]byte(json))
    if err != nil {
        println("Write to server failed:", err.Error())
		return err
    }

    println("write to server = ", json)

	return nil
}

